Attribute VB_Name = "modLookupCLSID"
Option Explicit
'***************************************************************
' (c) Copyright 2000 Matthew J. Curland
'
' This file is from the CD-ROM accompanying the book:
' Advanced Visual Basic 6: Power Techniques for Everyday Programs
'   Author: Matthew Curland
'   Published by: Addison-Wesley, July 2000
'   ISBN: 0-201-70712-8
'   http://www.PowerVB.com
'
' You are entitled to license free distribution of any application
'   that uses this file if you own a copy of the book, or if you
'   have obtained the file from a source approved by the author. You
'   may redistribute this file only with express written permission
'   of the author.
'
' This file depends on:
'   References:
'     VBoostTypes6.olb (VBoost Object Types (6.0))
'     TLBTypes.olb (VBoost: Type Library Types and Interfaces)
'     VBoost6.Dll (VBoost Object Implementation (6.0)) (optional)
'   Files:
'     VBoost.Bas (optional)
'   Minimal VBoost conditionals:
'     VBOOST_INTERNAL = 1 : VBOOST_CUSTOM = 1
'   Conditional Compilation Values:
'     NOVBOOST = 1 'Removes VBoost dependency
'
' This file is discussed in Chapter 7.
'***************************************************************
Private Type OwnedTypeAttr
    Owner As ArrayOwner
    pSA() As TYPEATTR
End Type
Private m_DerefTYPEATTR As OwnedTypeAttr

Public Function CLSIDFromFileAndClassName(strDllPath As String, strClassName As String) As CLSID
Dim ptinfo As ITypeInfo
Dim ptcomp As ITypeComp
Dim ptattr As TYPEATTRPtr
    With m_DerefTYPEATTR
        If m_DerefTYPEATTR.Owner.SA.cDims = 0 Then
            InitArrayOwner .Owner, LenB(.pSA(0)), 0
        End If
    End With
    With LoadTypeLibEx(strDllPath, REGKIND_NONE).GetTypeComp
        .BindType strClassName, 0, ptinfo, ptcomp
        With ptinfo
            ptattr = .GetTypeAttr
            With m_DerefTYPEATTR
                .Owner.SA.pvData = ptattr
                CLSIDFromFileAndClassName = .pSA(0).Guid
            End With
            .ReleaseTypeAttr ptattr
        End With
    End With
End Function

